{extend name="main"}
{block name="body"}
<div class="bg-white p-3 row mr-0 ml-0">
	<div class="col-12 col-sm-8">
		<el-form :model="form" @submit.native.prevent="submitForm" :rules="rules" ref="form" label-width="120px" :label-position="labelPosition">

		  <el-form-item label="头像" prop="headimg">
			<el-image
			  	v-if="form.headimg" 
			    style="width: 80px; height: 80px"
			    lazy
			    class="rounded-circle mr-2"
			    :src="form.headimg" 
			    :preview-src-list="[form.headimg]">
			</el-image>
		  	  <el-upload
				  class="avatar-uploader"
				  action="/uploadFiles"
				  name="file"
				  accept="image/*"
				  :data="{path:'admin/headimg'}"
				  :show-file-list="false"
				  :on-success="handleAvatarSuccess"
				  :on-error="handleAvatarError">
		  			<el-button size="small" type="primary">选择文件</el-button>
			  </el-upload>
		  </el-form-item>

		  <el-form-item label="昵称" prop="nickname">
		    <el-input v-model="form.nickname" class="col-12 col-sm-3 pl-0 pr-0" placeholder="Name"></el-input>
		  </el-form-item>

		  <el-form-item label="账号" prop="username">
		    <el-input v-model="form.username" class="col-12 col-sm-3 pl-0 pr-0" placeholder="UserName"></el-input>
		  </el-form-item>

		  <el-form-item label="密码" :prop="is_edit?'':'password'">
		    <el-input v-model="form.password" class="col-12 col-sm-3 pl-0 pr-0" :placeholder="is_edit?'Password,不填则不修改':'Password'"></el-input>
		  </el-form-item>

		  <el-form-item label="手机号" prop="mobile">
		    <el-input v-model="form.mobile" class="col-12 col-sm-3 pl-0 pr-0" placeholder="Mobile"></el-input>
		  </el-form-item>

		  <el-form-item label="邮箱" prop="email">
		    <el-input v-model="form.email" class="col-12 col-sm-3 pl-0 pr-0" placeholder="Email"></el-input>
		  </el-form-item>

		  <el-form-item label="其他联系方式" prop="other_contact">
		    <el-input type="textarea" v-model="form.other_contact" class="col-12 col-sm-4 pl-0 pr-0" placeholder="QQ:123456"></el-input>
		    <p class="small">ps:每行一种联系方式</p>
		  </el-form-item>

		  <el-form-item label="其他联系方式" prop="other_img">
			<el-image
			  	v-if="form.other_img" 
			    style="width: 120px; height: 120px"
			    lazy
			    class="mr-2"
			    :src="form.other_img" 
			    :preview-src-list="[form.other_img]">
			</el-image>
		  	  <el-upload
				  class="avatar-uploader"
				  action="/uploadFiles"
				  name="file"
				  accept="image/*"
				  :data="{path:'admin/other_img'}"
				  :show-file-list="false"
				  :on-success="handleAvatarSuccess"
				  :on-error="handleAvatarError">
		  			<el-button size="small" type="primary">选择文件</el-button>
			  </el-upload>
		  </el-form-item>

		  <el-form-item label="Openid" prop="openid">
		    <el-input v-model="form.openid" class="col-12 col-sm-3 pl-0 pr-0" placeholder="Openid"></el-input>
		    <p class="small">关注公众号》发送：“openid”关键词》复制返回的字符串（openid）</p>
		  </el-form-item>

		  <el-form-item>
		    <el-button type="primary" @click="submitForm('form')">立即保存</el-button>
		    <el-button @click="resetForm('form')">重置</el-button>
		  </el-form-item>
		</el-form>
	</div>
	<div class="col-12 col-sm-4">
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
	{notempty name="Find"}
	var url='/admin/editMy';
	var is_edit=true;
	var formData={:json_encode($Find,JSON_UNESCAPED_UNICODE)};
	{/notempty}
</script>
<script type="text/javascript">
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			labelPosition:'right',
			is_edit:is_edit,
			form:formData,
		    rules: {
		      role_id: [
		        { required: true, message: '请选择权限等级', trigger: 'blur' },
		      ],
		      nickname: [
		        { required: true, message: '请输入名称', trigger: 'blur' },
		        { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
		      ],
		      username: [
		        { required: true, message: '请设置账号', trigger: 'blur' },
		        { min: 6, max: 25, message: '长度在 6 到 25 个字符', trigger: 'blur' }
		      ],
		      password: [
		        { required: true, message: '请设置密码', trigger: 'blur' },
		        { min: 6, max: 25, message: '长度在 6 到 25 个字符', trigger: 'blur' }
		      ]
		    }
		},
		watch:{
		    view:XYBase.viewWatch
		},
		created(){
			XYBase.created(this);
		},
		methods:{
			handleAvatarSuccess:function(res, file) {
				if(res){
					if(res.code === 0){
						if(res.data.type == 'admin/headimg'){
							this.form.headimg=res.data.path;
						}else if(res.data.type == 'admin/other_img'){
							this.form.other_img=res.data.path;
						}
						XYBase.success(res.msg);
					}else{XYBase.error(res.msg);}
				}else{XYBase.error(XYBase.config.system_network_error)}
			},
			handleAvatarError:function(res, file) {
	          	XYBase.error(XYBase.config.system_network_error)
			},
			submitForm:function(formName) {
				var _this=this;
				var D=_this.form;
				_this.$refs[formName].validate((valid) => {
				  if (valid) {
					const loading = XYBase.openloading();
					$.ajax({
						url:url,
						data:D,
						type:'post',
						dataType:'json',
						success:function(ret){
					        loading.close();
					        if (ret) {
								if(ret.code == 0){
									XYBase.success(ret.msg);
									if(!_this.is_edit){
										_this.resetForm(formName);
									}
								}else{
									XYBase.msg(ret.msg);
								}
					        }else{
				          		XYBase.error(XYBase.config.system_network_error)
					        }
						},
						error:function(err){
					        loading.close();
				          	XYBase.error(XYBase.config.system_network_error)
						}
					});
				  } else {
					XYBase.warning('请先把表单填写完整。');
				    return false;
				  }
				});
			},
			resetForm:function(formName) {
				this.$refs[formName].resetFields();
			},
		}
	});
$(function(){
	reloadWindowSize();
	$(window).resize(function(){
		reloadWindowSize();
	});
});
function reloadWindowSize (argument) {
	var winW=$(window).width();
	if(winW <= 576){
		vm.labelPosition='top';
	}else{
		vm.labelPosition='right';
	}
}
</script>
{/block}